home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.052 < prev    next >
Encoding:
Text File  |  1989-08-20  |  8.0 KB  |  190 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIGS
  8. #52:    Loading and Special Memory
  9.  
  10. Revised by:    Eric Soldan                                          July 1989
  11. Written by:    Eric Soldan                                       January 1989
  12.  
  13. This Technical Note discusses strategies for preventing applications from 
  14. loading into special memory.
  15. Changes since January 1989:  Modified code sample so the Loader no longer 
  16. disposes of some segments before a Restart call is complete.
  17. _____________________________________________________________________________
  18.  
  19. The System Loader loads your application starting at the lowest memory 
  20. location possible.  If you allow your program to load into special memory, the 
  21. Loader first tries bank $01.  If your program cannot load into special memory, 
  22. it starts at bank $02.  Either way, the Loader progresses to higher banks, and 
  23. eventually, it may even try loading into bank $E1, which contains the super 
  24. hi-res screen.
  25.  
  26. The problem with allowing your application to load into special memory is that 
  27. the super hi-res screen is part of special memory.  If you have a desktop 
  28. application, part of your application may load into the super hi-res screen, 
  29. and when you try to start QuickDraw II, it fails because the screen memory is 
  30. already allocated.
  31.  
  32. When QuickDraw II fails because your program loaded into the SHR screen, it 
  33. seems reasonable to assume that the Loader put your program there because it 
  34. needed the RAM which special memory provides.  This logic seems to make sense, 
  35. but it is not completely reliable.  The Loader tries to put your program into 
  36. special memory before it tries purging dormant applications.  This means that 
  37. the more programs that run from the Finder that set the GS/OS or ProDOS 16 
  38. "restartable from memory" bit, the more likely it is that the next application 
  39. launched that can load into special memory will load into the super hi-res 
  40. screen.
  41.  
  42. For this reason, it is important not to let your application load into special 
  43. memory, or at least not load into the super hi-res screen.  If your 
  44. application is not allowed to load into special memory, then the Loader will 
  45. purge other dormant applications to make space for yours.  One way to 
  46. accomplish this is when linking your application.  You can set the "no special 
  47. memory" bit in the OMF KIND field of applications using OMF 2.0 or later, but 
  48. this also prohibits your application from using bank $01.
  49.  
  50. Another way to avoid loading into the super hi-res screen is to have your 
  51. initial segment allocate the super hi-res screen.  You can accomplish this by 
  52. starting QuickDraw II in your initial segment, then the rest of your program 
  53. cannot load into the already-allocated super hi-res screen.  This strategy 
  54. could fail if the initial segment loaded into the super hi-res screen, but 
  55. this is very unlikely and can be prevented by flagging the initial segment to 
  56. only load into non-special memory.  You can do this by setting the "no special 
  57. memory" bit in the KIND field only for the initial segment.
  58.  
  59.  
  60. Here's an example of such an initial segment in MPW IIGS format:
  61.  
  62. ************************************************************************
  63. *
  64. * You may wish to do this stuff in the initial segment of your
  65. * application.  The initial segment should be set so that it does not
  66. * load into special memory, or else it is possible that it would load
  67. * into the super hi-res screen.  If this occurred, then QuickDraw II would
  68. * not be able to be started.
  69. *
  70. * Once QuickDraw II is started, the super hi-res screen is taken,
  71. * therefore the rest of the application can not load into it.  Therefore,
  72. * special memory is generally an acceptable place for the rest of the
  73. * application to load, since the special memory needed for the screen
  74. * is already taken.
  75. *
  76. * If the performance of your application would be adversely affected
  77. * by memory fragmentation, then you should also consider purging
  78. * other dormant applications and dormant tools, and then compacting
  79. * memory.  This will prevent fragmentation as much as possible
  80. * while your application is loading.  It also has the cost of longer
  81. * startup time since some tools may have to be reloaded.  This is the
  82. * only way to be sure that tools that you don't want are removed
  83. * from memory before the rest of your application tries to load
  84. * around them.
  85. *
  86. * The Finder is a dormant application when your application is
  87. * launched.  This will cause the Finder to be thrown out of memory,
  88. * and it will have to be reloaded when your application is quit.
  89. *
  90. ************************************************************************
  91.  
  92.             case on
  93.  
  94.             include 'e16.memory'
  95.             include 'm16.memory'
  96.             include 'm16.quickdraw'
  97.  
  98.  
  99. screenMode         equ    $80
  100. AppMaxWidth        equ    160           ;Double this is your application
  101.                                         ;will print in BetterText mode.
  102. ******************
  103.  
  104.  
  105. initialScreen    PROC
  106.  
  107. myID               equ    1             ;long
  108. zpagehndl          equ    myID+4        ;long
  109.  
  110. stkAfterLocals     equ    zpagehndl+4
  111.  
  112. directReg          equ    stkAfterLocals
  113. retAddr            equ    directReg+2
  114. passedParms        equ    retAddr+3
  115.  
  116.                    phd                  ;Set up stack frame.
  117.                    tsc
  118.                    sec
  119.                    sbc    #stkAfterLocals-1
  120.                    tcs
  121.                    tcd
  122.                    pha
  123.                    _MMStartUp
  124.                    pla
  125.                    sta    myID          ;Get the userID
  126.  
  127.                    pha
  128.                    _HLockAll            ;Lock down the rest of ourselves, in
  129.                                         ;case we are being restarted.  The
  130.                                         ;loader does not prelock down stuff,
  131.                                         ;so we would be disposing of the rest
  132.                                         ;of ourselves.
  133.  
  134.                    pea    $1000
  135.                    _PurgeAll            ;Purge other dormant applications.
  136.                                         ;This is optional.
  137.                    pea    $4000
  138.                    _PurgeAll            ;Purge dormant tools.
  139.                                         ;This is optional.
  140.  
  141.                    _CompactMem          ;Clean up memory.  This is advised.
  142.  
  143.                    pha                  ;Make direct space for QuickDraw.
  144.                    pha
  145.                    pea    $300>>16      ;Hi-byte of $300 address.
  146.                    pea    $300
  147.                    pei    myID
  148.                    pea    attrLocked+attrFixed+attrPage+attrBank
  149.                    lda    #0
  150.                    pha
  151.                    pha
  152.                    _NewHandle
  153.                    plx
  154.                    stx    zpagehndl
  155.                    plx
  156.                    stx    zpagehndl+2
  157.                    bcc    @a
  158.                    ERRORDEATH 'Out of bank 0 memory'
  159.  
  160. @a                 lda    zpagehndl
  161.                    sta    >qdstarthndl  ;Used for disposing handle at shutdown.
  162.                    txa
  163.                    sta    >qdstarthndl+2
  164.                    lda    [zpagehndl]   ;Start up QuickDraw.  This protects
  165.                    pha                  ;screen ram from the rest of the
  166.                    pea    screenMode    ;application from loading into it.
  167.                    pea    AppMaxWidth
  168.                    pei    myID
  169.                    _QDStartUp
  170.                    bcc    @b
  171.                    ERRORDEATH 'Can''t start up QuickDraw'
  172. @b                                      ;Do title screen here.
  173.                    tsc
  174.                    clc
  175.                    adc    #stkAfterLocals-1
  176.                    tcs
  177.                    pld
  178.                    rtl
  179.  
  180. qdstarthndl        dc.l   0
  181.  
  182.                  ENDP
  183.                  END
  184.  
  185.  
  186. Further Reference:
  187. _____________________________________________________________________________
  188.     o    GS/OS Reference, Volume 1
  189.     o    MPW IIGS Tools Reference
  190.     o    APW Assembler Reference